<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="姓名" prop="sportsmanId">
        <el-select
          v-model="queryParams.sportsmanId"
          placeholder="请选择姓名"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in sprotsmanNameList"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="采集时间" prop="ctime">
        <el-date-picker
          clearable
          size="small"
          style="width: 200px"
          v-model="queryParams.ctime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择采集时间"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['training:sportsmanPhysicalQuality:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['training:sportsmanPhysicalQuality:remove']"
        >删除</el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="sportsmanPhysicalQualityList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="sportsmanName" />
      <!--            <el-table-column label="体重" align="center" prop="weight"/>-->
      <el-table-column label="卧推" align="center" prop="benchPress" />
      <!--<el-table-column label="卧推理想值" align="center" prop="benchPressIdeal" />
            <el-table-column label="3分钟卧推" align="center" prop="benchPress25kg3m" />
      <el-table-column label="3分钟卧推理想值" align="center" prop="benchPress25kg3mIdeal" />-->
      <el-table-column label="硬拉" align="center" prop="hardPull" />
      <!--      <el-table-column label="硬拉理想值" align="center" prop="hardPullIdeal" />-->
      <el-table-column label="卧拉" align="center" prop="wola" />
      <!--      <el-table-column label="卧拉理想值" align="center" prop="wolaIdeal" />-->
      <!--      <el-table-column label="3分钟卧拉" align="center" prop="wola30kg3m" />-->
      <!--      <el-table-column label="3分钟卧拉理想值" align="center" prop="wola30kg3mIdeal" />-->
      <el-table-column label="高翻" align="center" prop="highTurnover" />
      <!--      <el-table-column label="高翻理想值" align="center" prop="highTurnoverIdeal" />-->
      <el-table-column label="深蹲" align="center" prop="squat" />
      <!--      <el-table-column label="深蹲理想值" align="center" prop="squatIdeal" />-->
      <!--      <el-table-column label="3分钟深蹲(40公斤)" align="center" prop="squat40kg3m" />-->
      <!--      <el-table-column label="3分钟深蹲理想值(40公斤)" align="center" prop="squat40kg3mIdeal" />-->
      <el-table-column label="3分钟收腹" align="center" prop="pullStomachs3m" />
      <!--      <el-table-column label="3分钟收腹理想值" align="center" prop="pullStomachs3mIdeal" />-->
      <el-table-column label="腹肌耐力" align="center" prop="abdominalEndurance" />
      <!--      <el-table-column label="腹肌耐力理想值" align="center" prop="abdominalEnduranceIdeal" />-->
      <el-table-column label="引体向上" align="center" prop="pullUp" />
      <!--      <el-table-column label="引体向上理想值" align="center" prop="pullUpIdeal" />-->
      <el-table-column label="静力高架背肌" align="center" prop="staticElevatedDorsalMuscle" />
      <!--      <el-table-column label="静力高架背肌理想值" align="center" prop="staticElevatedDorsalMuscleIdeal" />-->
      <el-table-column label="背肌耐力" align="center" prop="backMuscleEndurance" />
      <!--      <el-table-column label="背肌耐力理想值" align="center" prop="backMuscleEnduranceIdeal" />-->
      <el-table-column label="垂直纵跳" align="center" prop="verticalJump" />
      <!--      <el-table-column label="垂直纵跳理想值" align="center" prop="verticalJumpIdeal" />-->
      <el-table-column label="坐立体前屈" align="center" prop="anteflexion" />
      <!--      <el-table-column label="坐立体前屈理想值" align="center" prop="anteflexionIdeal" />-->
      <el-table-column label="30米跑" align="center" prop="run30m" />
      <!--      <el-table-column label="30米跑理想值" align="center" prop="run30mIdeal" />-->
      <el-table-column label="3000米跑" align="center" prop="run3000m" />
      <!--      <el-table-column label="3000米跑理想值" align="center" prop="run3000mIdeal" />-->
      <el-table-column label="三级跳远" align="center" prop="threeStepJump" />
      <!-- <el-table-column label="采集时间" align="center" prop="ctime" /> -->
      <el-table-column label="采集时间" align="center" prop="ctime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ctime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <!--      <el-table-column label="三级跳远理想值" align="center" prop="threeStepJumpIdeal" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['training:sportsmanPhysicalQuality:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['training:sportsmanPhysicalQuality:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改sportsmanPhysicalQuality对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-col :span="6">
          <el-form-item label="姓名" prop="sportsmanId">
            <el-select
              v-model="form.sportsmanId"
              placeholder="请选择姓名"
              clearable
              size="small"
              style="width: 240px"
            >
              <el-option
                v-for="dict in sprotsmanNameList"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="卧推" prop="benchPress">
            <el-input v-model="form.benchPress" placeholder="请输入卧推" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="卧推理想值" prop="benchPressIdeal">
            <el-input v-model="form.benchPressIdeal" placeholder="请输入卧推理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟卧推" prop="benchPress25kg3m">
            <el-input v-model="form.benchPress25kg3m" placeholder="请输入3分钟卧推" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟卧推理想值" prop="benchPress25kg3mIdeal">
            <el-input v-model="form.benchPress25kg3mIdeal" placeholder="请输入3分钟卧推理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="硬拉" prop="hardPull">
            <el-input v-model="form.hardPull" placeholder="请输入硬拉" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="硬拉理想值" prop="hardPullIdeal">
            <el-input v-model="form.hardPullIdeal" placeholder="请输入硬拉理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="卧拉" prop="wola">
            <el-input v-model="form.wola" placeholder="请输入卧拉" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="卧拉理想值" prop="wolaIdeal">
            <el-input v-model="form.wolaIdeal" placeholder="请输入卧拉理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟卧拉" prop="wola30kg3m">
            <el-input v-model="form.wola30kg3m" placeholder="请输入3分钟卧拉" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟卧拉理想值" prop="wola30kg3mIdeal">
            <el-input v-model="form.wola30kg3mIdeal" placeholder="请输入3分钟卧拉理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="高翻" prop="highTurnover">
            <el-input v-model="form.highTurnover" placeholder="请输入高翻" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="高翻理想值" prop="highTurnoverIdeal">
            <el-input v-model="form.highTurnoverIdeal" placeholder="请输入高翻理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="深蹲" prop="squat">
            <el-input v-model="form.squat" placeholder="请输入深蹲" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="深蹲理想值" prop="squatIdeal">
            <el-input v-model="form.squatIdeal" placeholder="请输入深蹲理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟收腹" prop="pullStomachs3m">
            <el-input v-model="form.pullStomachs3m" placeholder="请输入3分钟收腹" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟收腹理想值" prop="pullStomachs3mIdeal">
            <el-input v-model="form.pullStomachs3mIdeal" placeholder="请输入3分钟收腹理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟深蹲(40公斤)" prop="squat40kg3m">
            <el-input v-model="form.squat40kg3m" placeholder="请输入3分钟深蹲(40公斤)" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3分钟深蹲理想值" prop="squat40kg3mIdeal">
            <el-input v-model="form.squat40kg3mIdeal" placeholder="请输入3分钟深蹲理想值(40公斤)" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="腹肌耐力" prop="abdominalEndurance">
            <el-input v-model="form.abdominalEndurance" placeholder="请输入腹肌耐力" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="腹肌耐力理想值" prop="abdominalEnduranceIdeal">
            <el-input v-model="form.abdominalEnduranceIdeal" placeholder="请输入腹肌耐力理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="引体向上" prop="pullUp">
            <el-input v-model="form.pullUp" placeholder="请输入引体向上" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="引体向上理想值" prop="pullUpIdeal">
            <el-input v-model="form.pullUpIdeal" placeholder="请输入引体向上理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="静力高架背肌" prop="staticElevatedDorsalMuscle">
            <el-input v-model="form.staticElevatedDorsalMuscle" placeholder="请输入静力高架背肌" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="静力高架背肌理想值" prop="staticElevatedDorsalMuscleIdeal">
            <el-input v-model="form.staticElevatedDorsalMuscleIdeal" placeholder="请输入静力高架背肌理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="背肌耐力" prop="backMuscleEndurance">
            <el-input v-model="form.backMuscleEndurance" placeholder="请输入背肌耐力" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="背肌耐力理想值" prop="backMuscleEnduranceIdeal">
            <el-input v-model="form.backMuscleEnduranceIdeal" placeholder="请输入背肌耐力理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="垂直纵跳" prop="verticalJump">
            <el-input v-model="form.verticalJump" placeholder="请输入垂直纵跳" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="垂直纵跳理想值" prop="verticalJumpIdeal">
            <el-input v-model="form.verticalJumpIdeal" placeholder="请输入垂直纵跳理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="坐立体前屈" prop="anteflexion">
            <el-input v-model="form.anteflexion" placeholder="请输入坐立体前屈" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="坐立体前屈理想值" prop="anteflexionIdeal">
            <el-input v-model="form.anteflexionIdeal" placeholder="请输入坐立体前屈理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="30米跑" prop="run30m">
            <el-input v-model="form.run30m" placeholder="请输入30米跑" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="30米跑理想值" prop="run30mIdeal">
            <el-input v-model="form.run30mIdeal" placeholder="请输入30米跑理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3000米跑" prop="run3000m">
            <el-input v-model="form.run3000m" placeholder="请输入3000米跑" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="3000米跑理想值" prop="run3000mIdeal">
            <el-input v-model="form.run3000mIdeal" placeholder="请输入3000米跑理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="三级跳远" prop="threeStepJump">
            <el-input v-model="form.threeStepJump" placeholder="请输入三级跳远" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="三级跳远理想值" prop="threeStepJumpIdeal">
            <el-input v-model="form.threeStepJumpIdeal" placeholder="请输入三级跳远理想值" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="采集时间" prop="ctime">
            <el-date-picker
              clearable
              size="small"
              style="width: 150px"
              v-model="form.ctime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择采集时间"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSportsmanPhysicalQuality,
  getSportsmanPhysicalQuality,
  delSportsmanPhysicalQuality,
  addSportsmanPhysicalQuality,
  updateSportsmanPhysicalQuality,
  exportSportsmanPhysicalQuality,
  listSportsmanName,
} from "@/api/training/sportsmanPhysicalQuality";

export default {
  name: "SportsmanPhysicalQuality",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // sportsmanPhysicalQuality表格数据
      sportsmanPhysicalQualityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //姓名字典集合
      sprotsmanNameList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sportsmanId: undefined,
        benchPress: undefined,
        benchPressIdeal: undefined,
        benchPress25kg3m: undefined,
        benchPress25kg3mIdeal: undefined,
        hardPull: undefined,
        hardPullIdeal: undefined,
        wola: undefined,
        wolaIdeal: undefined,
        wola30kg3m: undefined,
        wola30kg3mIdeal: undefined,
        highTurnover: undefined,
        highTurnoverIdeal: undefined,
        squat: undefined,
        squatIdeal: undefined,
        pullStomachs3m: undefined,
        pullStomachs3mIdeal: undefined,
        squat40kg3m: undefined,
        squat40kg3mIdeal: undefined,
        abdominalEndurance: undefined,
        abdominalEnduranceIdeal: undefined,
        pullUp: undefined,
        pullUpIdeal: undefined,
        staticElevatedDorsalMuscle: undefined,
        staticElevatedDorsalMuscleIdeal: undefined,
        backMuscleEndurance: undefined,
        backMuscleEnduranceIdeal: undefined,
        verticalJump: undefined,
        verticalJumpIdeal: undefined,
        anteflexion: undefined,
        anteflexionIdeal: undefined,
        run30m: undefined,
        run30mIdeal: undefined,
        run3000m: undefined,
        run3000mIdeal: undefined,
        threeStepJump: undefined,
        threeStepJumpIdeal: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sportsmanId: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getNameList();
  },
  methods: {
    /** 查询sportsmanPhysicalQuality列表 */
    getList() {
      this.loading = true;
      listSportsmanPhysicalQuality(this.queryParams).then((response) => {
        this.sportsmanPhysicalQualityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //赛事姓名集合
    getNameList() {
      this.loading = true;
      listSportsmanName(this.queryParams).then((response) => {
        this.sprotsmanNameList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        sportsmanId: undefined,
        benchPress: undefined,
        benchPressIdeal: undefined,
        benchPress25kg3m: undefined,
        benchPress25kg3mIdeal: undefined,
        hardPull: undefined,
        hardPullIdeal: undefined,
        wola: undefined,
        wolaIdeal: undefined,
        wola30kg3m: undefined,
        wola30kg3mIdeal: undefined,
        highTurnover: undefined,
        highTurnoverIdeal: undefined,
        squat: undefined,
        squatIdeal: undefined,
        pullStomachs3m: undefined,
        pullStomachs3mIdeal: undefined,
        squat40kg3m: undefined,
        squat40kg3mIdeal: undefined,
        abdominalEndurance: undefined,
        abdominalEnduranceIdeal: undefined,
        pullUp: undefined,
        pullUpIdeal: undefined,
        staticElevatedDorsalMuscle: undefined,
        staticElevatedDorsalMuscleIdeal: undefined,
        backMuscleEndurance: undefined,
        backMuscleEnduranceIdeal: undefined,
        verticalJump: undefined,
        verticalJumpIdeal: undefined,
        anteflexion: undefined,
        anteflexionIdeal: undefined,
        run30m: undefined,
        run30mIdeal: undefined,
        run3000m: undefined,
        run3000mIdeal: undefined,
        threeStepJump: undefined,
        threeStepJumpIdeal: undefined,
        ctime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加远动员物理属性";
      this.getNameList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getSportsmanPhysicalQuality(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改远动员物理属性";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            updateSportsmanPhysicalQuality(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addSportsmanPhysicalQuality(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除sportsmanPhysicalQuality编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delSportsmanPhysicalQuality(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有sportsmanPhysicalQuality数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportSportsmanPhysicalQuality(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        })
        .catch(function () {});
    },
  },
};
</script>